
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sj" tagdir="/WEB-INF/tags/spring-jquery-tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<script type="text/javascript">
	$(document).ready(function() {
		$('#pageTitle').text('<spring:message code="findPaymentrequest.heading" />');
		
		$("#editPaymentrequestForm").validate({
			rules : {
				paymentIdentifiedInformation : {
					number: true
				}
			}
		});
		$('.edit-paymentrequest-link').click(function() {
			loadDiv('content', 'showEditPaymentrequest.do?id=' + $(this).attr('paymentrequestId'));
		});		
		$('.process-paymentrequest-link').click(function() {
			loadDiv('content', 'processPaymentrequest.do?id=' + $(this).attr('paymentrequestId'));
		});
		
		$('#resetForm').click(function() {
			var inputs = $('#editPaymentrequestForm input[type="text"]');
			var select = $('#editPaymentrequestForm select');
			
			for(var i = 0; i < inputs.length; i++) {
				inputs[i].value='';	
			}
			
			for(var i = 0; i < select.length; i++) {
				select[i].value='';
			}
		});
	});
	$(document).ready(sortDropDownListByText);
	$(function() {
		$("#startDate").datepicker();
	});

	$(function() {
		$("#endDate").datepicker();
	});
	
		
	
	function sortDropDownListByText() {
	    // Loop for each select element on the page.
	  
	    $("select").each(function() {
	         
	        // Keep track of the selected option.
	        var selectedValue = $(this).val();
	 
	        // Sort all the options by text.
	        $(this).html($("option", $(this)).sort(function(a, b) {
	        	//return a.text == $(selectId + 'option:first').text ? -1 : a.text < b.text ? -1 : 1;
	        	
	           return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
	        }));
	 
	        // Select one option.
	        $(this).val(selectedValue);
	    });
	}
	$('.close-button').click(function() {
		loadDiv('content', 'refreshDashboard.do');
     });


		$('#loginFormSubmit').click(function() {		
		  var v1= $('#paymentIdentifiedInformation').val();
		  var v2= $('#createdBy\\.id').val();
		  var v3= $('#payee\\.id').val();
		  var v4= $('#statusCode').val();
		  var v5= $('#startAmount').val();
		  var v6= $('#endAmount').val();
		  var v7= $('#startDate').val();
		  var v8= $('#endDate').val();
		  var v9= $('#costcenternumber').val();
		  var v10= $('#accountcode\\.id').val();
		  var v11=$('#paymenttype\\.id').val();
		  if(v7!=''|| v8!=''){
		     if(v7==''){
			    alert("Please select valid start date query criteria. Start date can not be null. Leave blank both field  or enter valid range");
			     return false;
			   } else if(v8==''){
			    alert("Please enter valid start date query criteria. End date can not be null. Leave blank both field  or enter valid range");
			    return false;
			   } else if((new Date(v7)).getTime()> (new Date(v8)).getTime() ){
			     alert('Start date should be before end date');
			      return false;
			   }
			   
		  }
		  if(v5!=''|| v6!=''){
			   if(v5==''){
			    alert("Please enter valid amount query criteria. Start amount can not be null. Leave blank both field  or enter valid range");
			     return false;
			   } else if(v6==''){
			    alert("Please enter valid amount query criteria. End amount can not be null. Leave blank both field  or enter valid range");
			    return false;
			   }
		  
		  }
		  
		 if(v1!='' || v2!='' || v3!=''|| v4!='' || v5!='' || v6!='' || v7!='' || v8!='' || v9!='' || v10!='' || v11!=''){		    
		   return true;
		 }
		 alert("Please enter at least one filter criteria");
		 return false;
		});

   /*
    $('#check-all').click(function() {    
        var checkBox = $('#paymentRqst input:checkbox');
        for(var i = 0; i < checkBox.length; i++) {
     	   checkBox[i].checked = this.checked;
        }
 	});*/
    
</script>
<div id="findPaymentReqDonorDiv" >
	<form:form name="editPaymentrequestForm" id="editPaymentrequestForm" action="findResultPaymentrequest.do" method="post" modelAttribute="paymentrequest">
		<form:hidden path="id" />
	    <div class="main_form">
	    	<div class="form_head">
	    		<a href="#" class="close-button gray_btn floatR" tabindex="-1">Close Form</a><br class="clear" />
	    	</div>
	        <div class="form_cont">
				<table cellspacing="5" width="100%">
					<tr class="row">
						<td class="input-field" colspan="5">
							<%@ include file="/common/messages.jsp" %>
						</td>
					</tr>		  
					<tr class="row">
						<td class="label"><spring:message code="editPaymentrequest.label.paymentIdentifiedInformation" /></td>
						<td class="input-field">
							<form:input path="paymentIdentifiedInformation" cssClass="input-full-width text_white" tabindex="1"/>
							<form:errors path="paymentIdentifiedInformation" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="findPaymentrequest.label.createdBy" /></td>
						<td class="input-field">
							<form:select path="createdBy.id" cssClass="text_white" tabindex="6">
								<form:option value="" label="Select" />
								<form:options items="${userList}" itemValue="id" itemLabel="fullName" />
							</form:select>
							<form:errors path="createdBy.id" cssClass="error" />
						</td>
					</tr>
				
					<tr class="row">
						<td class="label"><spring:message code="editPaymentrequest.label.payee" /></td>
						<td class="input-field">
							<form:select path="payee.id" cssClass="text_white" tabindex="2">
								<form:option value="" label="Select" />
								<form:options items="${payeeList}" itemValue="id" itemLabel="payeeName" />
							</form:select>
							<form:errors path="payee.id" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editPaymentrequest.label.statusCode" /></td>
						<td class="input-field">
							<form:select path="statusCode" cssClass="text_white" tabindex="7">
						        <form:option value="" label="Select" />
								<form:option value="New" label="1) New" />
								<form:option value="In Finance" label="2) In Finance" />
								<form:option value="Awaiting Signature" label="3) Awaiting Signature" />
								<form:option value="Pending Payment" label="4) Pending Payment" />
								<form:option value="Paid" label="5) Paid" />
								<form:option value="Rejected" label="6) Rejected" />
								<form:option value="Cancel Requested" label="7) Cancel Requested" />
								<form:option value="Resubmitted" label="8) Resubmitted"/>
								<!--form:option value="Inactive" label="9) Inactive" /-->																
								<form:option value=" Cancelled" label=" 9) Cancelled" />
							</form:select></td>
							<form:errors path="statusCode" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editPaymentrequest.label.AmountBetween" /></td>
						<td class="input-field">
							<form:input path="startAmount" cssClass="input-full-width text_white" tabindex="3"/>
							<form:errors path="startAmount" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label">And</td>
						<td class="input-field">
							<form:input path="endAmount" cssClass="input-full-width text_white" tabindex="8"/>
							<form:errors path="endAmount" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editPaymentrequest.label.dateBetween" /></td>
						<td class="input-field">
							<form:input path="startDate" cssClass="input-full-width text_white" tabindex="9"/></td>
							<form:errors path="startDate" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label">And</td>
						<td class="input-field">
							<form:input path="endDate" cssClass="input-full-width text_white" />
							<form:errors path="endDate" cssClass="error" />
						</td>
					</tr>
					 <tr class="row">
						<td class="label"><spring:message code="editCipeproject.label.costCenter" /></td>
						<td class="input-field">
							<form:select path="costcenternumber" cssClass="text_white" tabindex="4">
								<form:option value="" label="Select" />
								<form:options items="${projectList}" itemValue="id" itemLabel="costCenterNumber" />
							</form:select>
							<form:errors path="paymentIdentifiedInformation" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editAccountCode.label.displayName" /></td>
						<td class="input-field">
							<form:select path="accountcode.id" cssClass="text_white" tabindex="10">
								<form:option value="" label="Select" />
								<form:options items="${accountCodeList}" itemValue="id" itemLabel="description" />
							</form:select>
							<form:errors path="accountcode" cssClass="error" />
						</td>
					</tr>
					
					<tr>
	                	<td class="label"><spring:message code="editPaymentrequest.label.paymentrequesttype" /></td>
	                	<td>	<form:select path="paymenttype.id" cssClass="input-full-width-req text_white" tabindex="5">
						       	<form:option value="" label="Select" tabindex="11"/>
								<form:options items="${paymenttypeList}" itemValue="id" itemLabel="paymenttypename" />
							</form:select></td>
	                	<td width="50">&nbsp;</td>
	                	<td class="label">&nbsp;</td>
	                	<td></td>
	              	</tr>
					<tr class="row">
						<td class="input-field" align="center" colspan="5">
							<sj:submit id="loginFormSubmit" cssClass="blue_btn" target="findPaymentReqDonorDiv" key="findDonoraward.button.search" validate="true" tabindex="-1"/>
							<input id="resetForm" type="button" class="blue_btn" value="<spring:message code='button.resetSearch' />" tabindex="-1" />
						</td>
					</tr>
				</table>

				<div id="paymentReqListDiv" class="hastable" style="overflow: auto">
				<table class="tablesorter">
			
				 <c:choose>
					<c:when test="${!empty paymentrequestList}">
						<thead>

						<c:if test="${messgae!='null'}">
									<tr>
									<th align="center" colspan="13"><font size="4"><c:out value="${message}"></c:out></font></th>
									</tr>
								</c:if>							
							<!--tr><th nowrap><input type="checkbox" id="check-all">&#10;<spring:message code="common.select.all"/></th -->
								<th><spring:message code="paymentrequestList.table.heading.processPaymentRequest" /></th>
								<th><spring:message code="paymentrequest.id"/></th>
								<th><spring:message code="paymentrequestList.table.heading.createdBy"/></th>
								<th><spring:message code="label.creationDate"/></th>
								<th><spring:message code="common.number.days.open"/></th>
								<th><spring:message code="editDonoraward.label.amount"/></th>			
								<th><spring:message code="label.type" /></th>
								<th><spring:message code="paymentrequestList.table.heading.statusCode"/></th>
								<th><spring:message code="paymentrequestList.table.heading.payee"/></th>
								<th><spring:message code="paymentrequestList.table.heading.paymentmethod"/></th>
								<th><spring:message code="paymentrequestList.table.heading.paymentConfirmationNumber"/></th>
								<th><spring:message code="paymentrequestList.table.heading.purposeOfExpenditure"/></th>
							</tr>
						</thead>		
					<tbody id="paymentRqst">
						<c:forEach items="${paymentrequestList}" var="paymentrequest">
							<tr>
							    <!--td><input type="checkbox" name="check_element" value="${paymentrequest.id}"></td-->
								<td><a href="javascript://" class="blue_btn process-paymentrequest-link" paymentrequestId="${paymentrequest.id}"><spring:message code="paymentrequestlist.table.link.process" /></a></td>
								<td><a href="javascript://" class="edit-paymentrequest-link" paymentrequestId="${paymentrequest.id}">${paymentrequest.id}</a></td>
								<td>${paymentrequest.createdBy.fullName}</td>
								<td><fmt:formatDate value="${paymentrequest.invoiceRequestDate}" pattern="DD/MM/YYYY"/></td>
								<td>${paymentrequest.paymentConfirmationNumber}</td>
								<!-- <td><a href="javascript://" class="edit-paymentrequest-link" paymentrequestId="${paymentrequest.id}">${paymentrequest.paymentIdentifiedInformation}</a></td> -->
								<td><fmt:formatNumber type="currency" value="${paymentrequest.amount}" pattern="$#,##0;"/></td>									
								<td>${paymentrequest.paymenttype.paymenttypename}</td>
								<td>${paymentrequest.statusCode}</td>
								<td>${paymentrequest.payee.payeeName}</td>
								<td>${paymentrequest.paymentmethod}</td>					
								<td>${paymentrequest.invoicenumber}</td>
								<td>${paymentrequest.purposeOfExpenditure}</td>
			
							</tr>
						</c:forEach>
						    <!--tr align="center"><td align="left" colspan="12"><input type="button" class="blue_btn" name="view"  value="View Selected Payment Requests" align="center" tabindex="-1"><input type="button" class="blue_btn" name="view" value="Process Payment Request" align="center" tabindex="-1"></td></tr-->
							</c:when>
							<c:otherwise>
							<c:if test="${ !empty param.action}">					  
								   <tr><td colspan="12"> Your query has returned 0 records </td></tr>
								 </c:if>  
							</c:otherwise>
				</c:choose>	
			
					</tbody>
				</table>
				</div>
				<div id="paymentrequestListPager"></div>
					
			</div>
		</div>
	</form:form>
</div>
